///////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
#include <Util.h>
#include <string.h>

//-----------------------------------------------------------------------------

void rtrim ( std::string &str, std::string sep )
{
	size_t endpos = str.find_last_not_of( sep.c_str() );
	if( std::string::npos != endpos )
	{
		str = str.substr( 0, endpos+1 );
	}
}

//-----------------------------------------------------------------------------

void ltrim ( std::string &str, std::string sep )
{
	size_t startpos = str.find_first_not_of( sep.c_str() );
	if( std::string::npos != startpos )
	{
		str = str.substr( startpos );
	}
}

//-----------------------------------------------------------------------------

void trim ( std::string &str, std::string sep )
{
	ltrim ( str, sep );
	rtrim ( str, sep );
}

//-----------------------------------------------------------------------------

std::string extractWord ( std::string &str, std::string sep )
{
	ltrim ( str, sep );
	std::string word = str;
	size_t pos = str.find_first_of( sep.c_str() );
	if( std::string::npos != pos )
	{
		word = str.substr( 0, pos );
		str.erase ( 0, pos );
	}else{
		str.clear ();
	}
	return word;
}

//-----------------------------------------------------------------------------

int getIndexGLTexture ( GLenum idx )
{
	if ( idx == GL_TEXTURE0 ) return 0;
	else if ( idx == GL_TEXTURE1 ) return 1;
	else if ( idx == GL_TEXTURE2 ) return 2;
	else if ( idx == GL_TEXTURE3 ) return 3;
	else if ( idx == GL_TEXTURE4 ) return 4;
	else if ( idx == GL_TEXTURE5 ) return 5;
	else if ( idx == GL_TEXTURE6 ) return 6;
	else if ( idx == GL_TEXTURE7 ) return 7;
	else if ( idx == GL_TEXTURE8 ) return 8;
	else if ( idx == GL_TEXTURE9 ) return 9;
	else if ( idx == GL_TEXTURE10 ) return 10;
	else if ( idx == GL_TEXTURE11 ) return 11;
	else if ( idx == GL_TEXTURE12 ) return 12;
	else if ( idx == GL_TEXTURE13 ) return 13;
	else if ( idx == GL_TEXTURE14 ) return 14;
	else if ( idx == GL_TEXTURE15 ) return 15;
	else if ( idx == GL_TEXTURE16 ) return 16;
	else if ( idx == GL_TEXTURE17 ) return 17;
	else if ( idx == GL_TEXTURE18 ) return 18;
	else if ( idx == GL_TEXTURE19 ) return 19;
	else if ( idx == GL_TEXTURE20 ) return 20;
	else if ( idx == GL_TEXTURE21 ) return 21;
	else if ( idx == GL_TEXTURE22 ) return 22;
	else if ( idx == GL_TEXTURE23 ) return 23;
	else if ( idx == GL_TEXTURE24 ) return 24;
	else if ( idx == GL_TEXTURE25 ) return 25;
	else if ( idx == GL_TEXTURE26 ) return 26;
	else if ( idx == GL_TEXTURE27 ) return 27;
	else if ( idx == GL_TEXTURE28 ) return 28;
	else if ( idx == GL_TEXTURE29 ) return 29;
	else if ( idx == GL_TEXTURE30 ) return 30;
	else if ( idx == GL_TEXTURE31 ) return 31;
	return -1;
}

//-----------------------------------------------------------------------------

GLenum getGLTexture ( int idx )
{
	if ( idx == 0 ) return GL_TEXTURE0;
	else if ( idx == 1 ) return GL_TEXTURE1;
	else if ( idx == 2 ) return GL_TEXTURE2;
	else if ( idx == 3 ) return GL_TEXTURE3;
	else if ( idx == 4 ) return GL_TEXTURE4;
	else if ( idx == 5 ) return GL_TEXTURE5;
	else if ( idx == 6 ) return GL_TEXTURE6;
	else if ( idx == 7 ) return GL_TEXTURE7;
	else if ( idx == 8 ) return GL_TEXTURE8;
	else if ( idx == 9 ) return GL_TEXTURE9;
	else if ( idx == 10 ) return GL_TEXTURE10;
	else if ( idx == 11 ) return GL_TEXTURE11;
	else if ( idx == 12 ) return GL_TEXTURE12;
	else if ( idx == 13 ) return GL_TEXTURE13;
	else if ( idx == 14 ) return GL_TEXTURE14;
	else if ( idx == 15 ) return GL_TEXTURE15;
	else if ( idx == 16 ) return GL_TEXTURE16;
	else if ( idx == 17 ) return GL_TEXTURE17;
	else if ( idx == 18 ) return GL_TEXTURE18;
	else if ( idx == 19 ) return GL_TEXTURE19;
	else if ( idx == 20 ) return GL_TEXTURE20;
	else if ( idx == 21 ) return GL_TEXTURE21;
	else if ( idx == 22 ) return GL_TEXTURE22;
	else if ( idx == 23 ) return GL_TEXTURE23;
	else if ( idx == 24 ) return GL_TEXTURE24;
	else if ( idx == 25 ) return GL_TEXTURE25;
	else if ( idx == 26 ) return GL_TEXTURE26;
	else if ( idx == 27 ) return GL_TEXTURE27;
	else if ( idx == 28 ) return GL_TEXTURE28;
	else if ( idx == 29 ) return GL_TEXTURE29;
	else if ( idx == 30 ) return GL_TEXTURE30;
	else if ( idx == 31 ) return GL_TEXTURE31;
	return -1;
}

//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
